package com.du.design.observer;

import java.util.ArrayList;
import java.util.List;

/**
 * @desc:
 * @author: shuangdu
 * @date: 2022/1/7
 * @since: 1.8
 */
public class WeatherStation implements Subject {

    private List<Observe> observeList = new ArrayList<>();

    // 温度
    private Double temperature;

    // 湿度
    private Double humidity;


    @Override
    public void addObserve(Object observe) {
        observeList.add((Observe) observe);
        System.out.println("添加观察者："+ observe.getClass().getSimpleName());
    }

    @Override
    public void removeObserve(Object observe) {
        observeList.remove(observe);
        System.out.println("删除观察者："+ observe.getClass().getSimpleName());
    }

    @Override
    public void notifyObserves() {
        for (Observe observe : observeList) {
            observe.update();
        }
    }

    public Double getTemperature() {
        return temperature;
    }

    public void setTemperature(Double temperature) {
        this.temperature = temperature;
    }

    public Double getHumidity() {
        return humidity;
    }

    public void setHumidity(Double humidity) {
        this.humidity = humidity;
    }

    public String getInfo() {
        return "温度：" + temperature + ", 湿度：" + humidity;
    }

}
